﻿<?php  
include("conn.php");
mysql_query('SET NAMES UTF8'); 

	  

		class MyPrizeBean
		{
			public $title;
			public $price;
			public $yuanjia;
			public $goodsid;
			public $images;
			public $srcimages;
			public $defaultImgOrd;
			public $goumaishu;
			public $content;
			public $summary;
			public $xuanxiang;
			public $xuanprice;
			public $shopid;
			public $delivery_time;
			public $xiaoliang;
			public $services;
			public $type;
			public $can_fanquan;
			public $distribution_fee;
			public $start_num;
			public $Freight_dir;
			public $fareml;
			public $zixilie;
			public $defaultXQTuOrd;
			public $xiangQingTu;
			public $shangjia;
			public $start_num_desc;
			public $goods_dir;
			public $shop_sname;
			public $shop_slogo;

			function __construct($title,$price,$yuanjia,$goodsid,$images,$defaultImgOrd,$goumaishu,$content,$summary,$xuanxiang,$xuanprice,$shopid,$delivery_time,$xiaoliang,$services,$type,$can_fanquan,$distribution_fee,$start_num,$Freight_dir,$fareml,$zixilie,$defaultXQTuOrd,$xiangQingTu,$shangjia,$srcimages,$start_num_desc,$goods_dir,$shop_sname,$shop_slogo)
			{
				$this->title      = $title;
				$this->price     = $price;
				$this->yuanjia     = $yuanjia;
				$this->goodsid     = $goodsid;
				$this->images     = $images;
				$this->defaultImgOrd     = $defaultImgOrd;
				$this->goumaishu     = $goumaishu;
				$this->content     = $content;
				$this->summary     = $summary;
				$this->xuanxiang     = $xuanxiang;
				$this->xuanprice     = $xuanprice;
				$this->shopid     = $shopid;
				$this->delivery_time     = $delivery_time;
				$this->xiaoliang     = $xiaoliang;
				$this->services     = $services;
				$this->type     = $type;
				$this->can_fanquan     = $can_fanquan;
				$this->distribution_fee     = $distribution_fee;
				$this->start_num     = $start_num;
				$this->Freight_dir     = $Freight_dir;
				$this->fareml = $fareml;
				$this->zixilie = $zixilie;
				$this->defaultXQTuOrd = $defaultXQTuOrd;
				$this->xiangQingTu = $xiangQingTu;
				$this->shangjia = $shangjia;
				$this->srcimages = $srcimages;
				$this->start_num_desc = $start_num_desc;
				$this->goods_dir = $goods_dir;
				$this->shop_sname = $shop_sname;
				$this->shop_slogo = $shop_slogo;
			}
		}


	if(!$_REQUEST[goodsid]){
		echo json_encode(array('code'=>-100,'msg'=>'商品id不能为空'));
		exit;
	}

	$prize = array();
	$rert30=mysql_query("select * from goods  where goodsid='".$_REQUEST[goodsid]."'");
	$rowf=mysql_fetch_array($rert30);
	// 判断商品是否属于快购商品,若属于,则需返回配送时间
	$query = mysql_query("select * from zifenlei where id=".$rowf[zixilie]);
	$zifenlei = mysql_fetch_assoc($query);
	if ($zifenlei[type] == 1) {
		$delivery_time = $rowf[delivery_time];
	}else{
		$delivery_time = '';
	}
	// 判断商品是否属于快购商品,若属于,则需返回配送时间 end

      //选项
	$xuan=array();
	$xuanjia=array();
	$rert3s=mysql_query("select * from goodsselect where  goodsid='".$rowf['goodsid']."' order by selectid desc limit 0,1"); 
    $likes=mysql_fetch_array($rert3s);

    if($likes!=false){ 
			        
				  $x=$likes[title];
				  $xjia=$likes[price];
				  $rert3=mysql_query("select * from goodsselect where  goodsid='".$rowf['goodsid']."' order by selectid desc limit 1,20 "); 
		          while($like=mysql_fetch_array($rert3))
				  {
				  
					  $x.=",".$like[title];
					  $xjia.=",".$like[price];
				  }
				  
				   
				   $xuan=explode("," ,$x);
				   
				   $xuanjia=explode("," ,$xjia);
		   
	}//选项 end
		   
		   //商品缩略图
		   $imesg=array();
           $imes=$rowf['images'];
		   $imesg=explode("," ,$imes);
		   //商品原图
		   $srcimesg=array();
           $srcimes=$rowf['srcimages'];
		   $srcimesg=explode("," ,$srcimes);

// 查找商品所属详情 


// 查找商品是属于海淘还是快购
$query = mysql_query("select * from zifenlei where id=".$rowf[zixilie]);
$zixilie = mysql_fetch_assoc($query);

if ($zixilie[type] == 0) {
	$query = mysql_query("select * from categroy_type where id=(select categroy_type_id from categroy where cateid=".$rowf[xilie].")");
	$categroy_type = mysql_fetch_assoc($query);

	$categroy_type[is_logistics];

}elseif ($zixilie[type] == 1) {
	$query = mysql_query("select * from categroy_type where id=(select categroy_type_id from categroy where cateid=".$rowf[xilie].")");
	$categroy_type = mysql_fetch_assoc($query);
}

// 查找买家服务
$query = mysql_query("select * from zifenlei where id=".$rowf[zixilie]);
$zixilie = mysql_fetch_assoc($query);

$query = mysql_query("select htservice,kgservice,distribution_fee from shop where shopid=".$rowf[shopid]);
$shop = mysql_fetch_assoc($query);

if ($zixilie[type] == 0 ) {
	$htservice = explode(',', $shop[htservice]);
	$htlen = count($htservice);
	$services = array();
	for ($i=0; $i < $htlen; $i++) { 
		$sql = mysql_query("select name from buyer_service where id=".$htservice[$i]);
		$shop = mysql_fetch_assoc($sql);
		$services[] = $shop[name];
	}
}elseif ($zixilie[type] == 1 ) {
	$kgservice = explode(',', $shop[kgservice]);
	$kglen = count($kgservice);
	$services = array();
	for ($i=0; $i < $kglen; $i++) { 
		$sql = mysql_query("select name from buyer_service where id=".$kgservice[$i]);
		$shop = mysql_fetch_assoc($sql);
		$services[] = $shop[name];
	}
}
// 查找买家服务 end

// 查找商品类型（海淘或快购）
$query = mysql_query("select type from zifenlei where id=".$rowf[zixilie]);

$type = mysql_fetch_assoc($query);
$type = $type[type];
// 查找商品类型（海淘或快购） end

// 查找运费
$query = mysql_query("select name from fareml where id=".$rowf['muid']);
$mu = mysql_fetch_assoc($query);
$mu = $mu["name"];
//查找运费 end

$can_fanquan = (bool)$rowf[can_fanquan];
$rowf['Freight_dir'] = empty($rowf['Freight_dir']) ? '':$rowf['Freight_dir'];
$resultData = array();
$resultData['code'] = 200;
//$rowf[content]
$queryShop=mysql_query("select name,images from shop where shopid=".$rowf[shopid]);
//$Db->table()->field('name,images')->where('shopid',$rowf[shopid])->select();
$row=array();
$rows=mysql_fetch_array($queryShop,MYSQL_ASSOC);
$row['shopname']=$rows['name'];
$row['shoplogo']=$rows['images'];

// 记录用户浏览记录
$userid = !empty($_REQUEST['userid'])?$_REQUEST['userid']:null;
$goodsid = !empty($_REQUEST['goodsid'])?$_REQUEST['goodsid']:null;
$scan=mysql_fetch_assoc( mysql_query('select * from user where userid='.$userid) )['record_scan'];

// 记录除重
if($scan){
	$arr =implode(',', array_unique(explode(',',ltrim($scan,','))));
}else{
	$arr=$scan?$scan:'';	
}

$goods = mysql_fetch_assoc( mysql_query('select * from goods where goodsid='.$goodsid) );
if($userid && $goodsid){
	$arrs=$userid.','.$goodsid.','.$goods['shopid'].',"'.$goods['title'].'","'.$goods['images'].'","'.$goods['yuanjia'].'","'.$goods['price'].'","'.$_REQUEST['position'].'"';
	if( !mysql_fetch_assoc(mysql_query('select * from scan_record where uid='.$userid.' and goodsid='.$goodsid.'')) ){
		$res=mysql_query('insert into scan_record(uid,goodsid,sid,title,images,yuanjia,price,position) values('.$arrs.')');
	}		
}

if($rowf['Freight_dir'] == null) {
	$yunfei = mysql_fetch_assoc(mysql_query('select Freight_dir from shop where shopid = ' . $rowf['shopid']));
	$rowf['Freight_dir'] = $yunfei[0];
}
 
$resultData['data'] = new MyPrizeBean($rowf[title],$rowf[price],$rowf[yuanjia],$rowf[goodsid],$imesg,$rowf[defaultImgOrd],$rowf[xiaoliang],'',$rowf[summary],$xuan,$xuanjia,$rowf[shopid],$delivery_time,$rowf[xiaoliang],$services,$type,$can_fanquan,$mu,$rowf['start_num'],$rowf['Freight_dir'],$rowf['muid'],$rowf[zixilie],$rowf[defaultXQTuOrd],$rowf[xiangQingTu],$rowf[shangjia],$srcimesg,$rowf[start_num_desc],$rowf['goods_dir'],$row['shopname'],$row['shoplogo']);
		
echo json_encode($resultData);
?>